<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	item		= Request("findItem")
	types	= Request("findType")

	SQLTitle = "-- ■■■■ 원자재 정보 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If item <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " (A.srcNm LIKE '%" & item & "%' OR A.srcCd LIKE '%" & item & "%') "
	End If 
	If types <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " A.type = '" & types & "' "
	End If 

	If addSql <> "" Then 
		addSql = " WHERE " & addSql 
	End If 

	SQL = "SELECT A.srcCd, A.srcNm, A.srcSeq, A.flag, A.type, B.restQty, A.prdInfo " & _
			"	FROM tblSrc A LEFT JOIN (SELECT srcCd, (SUM(input) - SUM(output)) restQty FROM tblSrcInOut WHERE flag='Y' GROUP BY srcCd) B ON A.srcCd=B.srcCd " & addSql & _
			"	ORDER BY A.type, A.flag DESC, A.srcSeq" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<Source>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
			
			restQty = "&nbsp;"
			restQty = rs("restQty")
			If ISNULL(restQty) = true Then
				restQty = "&nbsp;"
			End If  
			Response.write "	<Src>" & vbcrlf
				Call mkXMLNode("srcCd", rs("srcCd"), 2)
				Call mkXMLNode("srcNm", rs("srcNm"), 2)
				Call mkXMLNode("restQty", restQty, 2)
				Call mkXMLNode("srcSeq", rs("srcSeq"), 2)
				Call mkXMLNode("prdInfo", rs("prdInfo"), 2)
				Call mkXMLNode("type", rs("type"), 2)
				Call mkXMLNode("flag", Rs("flag"), 2)
			Response.write "	</Src>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</Source>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>